package com.itdianzi.service.cargo.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itdianzi.dao.cargo.ShippingOrderDao;
import com.itdianzi.domain.cargo.ShippingOrder;
import com.itdianzi.domain.cargo.ShippingOrderExample;
import com.itdianzi.service.cargo.ShippingOrderService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service
public class ShippingOrderServiceImpl implements ShippingOrderService {

    @Autowired
    private ShippingOrderDao shippingOrderDao;

    /*
    *   新建委托单
    * */
    @Override
    public void save(ShippingOrder shippingOrder) {
        shippingOrder.setCreateTime(new Date());
        shippingOrder.setState(0);//新建的是草稿状态
        shippingOrderDao.insertSelective(shippingOrder);
    }

    /*ShippingOrder
    *   分页查询委托单，并分页展示
    * */
    @Override
    public PageInfo findAll(ShippingOrderExample shippingOrderExample, int page, int size) {
        PageHelper.startPage(page, size);
        List<ShippingOrder> shippingOrderList = shippingOrderDao.selectByExample(shippingOrderExample);
        System.out.println(shippingOrderList);
        return new PageInfo(shippingOrderList);
    }

    /*
    *   根据id查询委托单
    * */
    @Override
    public ShippingOrder findById(String id) {
        ShippingOrder shippingOrder = shippingOrderDao.selectByPrimaryKey(id);
        return shippingOrder;
    }

    /*
    *   修改委托单
    * */
    @Override
    public void update(ShippingOrder shippingOrder) {
        shippingOrderDao.updateByPrimaryKeySelective(shippingOrder);
    }

    /*
    *   删除委托单
    * */
    @Override
    public void delete(String id) {
        shippingOrderDao.deleteByPrimaryKey(id);
    }

}
